//
//  LeftSideViewController.m
//  YouthOlympic2014
//
//  Created by xiangpaopao on 14-6-18.
//  Copyright (c) 2014年 mitian. All rights reserved.
//

#import "LeftSideViewController.h"
#import "LeftMenuCell.h"
#import "UIViewController+MMDrawerController.h"
#import "LandScapeMoviePlayerViewController.h"
#import "HomeViewController.h"
#import "BaseNavViewController.h"
#import "XYAlertView.h"
//
#import "HCYOGDynamic.h"
#import "HCPlaySteam.h"
#import "HCFacilityDisplayMain.h"
#import "HCYOGVillage.h"
#import "ShowVenuesViewController.h"

@interface LeftSideViewController ()<SelectVenueProtocol>

@property (nonatomic, strong) NSArray *titleArr;
@property (nonatomic, strong) NSArray *colorArr;
@property (nonatomic, strong) NSArray *imgArr;
@property (nonatomic, strong) NSIndexPath *curIndex;

@property (nonatomic, strong) NSArray *centerViewControllers;



@end

@implementation LeftSideViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)selectVenue:(NSString *)sceneNoString
{
    ShowVenuesViewController *hcVC = [[ShowVenuesViewController alloc]init];
    hcVC.SceneNo = sceneNoString;
    [self.navigationController pushViewController:hcVC animated:YES];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //self.menuView.delegate = self;
    _titleArr = [NSArray arrayWithObjects:
                 NSLocalizedString(@"首页", nil),
                 NSLocalizedString(@"CEP活动", nil),
                 NSLocalizedString(@"青奥动态", nil),
                 NSLocalizedString(@"青奥村", nil),
                 NSLocalizedString(@"3D场馆", nil),
                 NSLocalizedString(@"语言帮助", nil),
                 NSLocalizedString(@"CCTV", nil),
                 NSLocalizedString(@"旅游资讯", nil),
                 nil];
    _colorArr = [NSArray arrayWithObjects:HEX2UIColor(0xabcd03),
                 HEX2UIColor(0xee2c4e),
                 HEX2UIColor(0x00a0e9),
                 HEX2UIColor(0x00a73c),
                 HEX2UIColor(0x3aa462),
                 HEX2UIColor(0xf8b90c),
                 HEX2UIColor(0x0669b5),
                 HEX2UIColor(0xe5007f),nil];
    _imgArr = [NSArray arrayWithObjects:@"l_item_1",@"l_item_8",@"l_item_6",@"l_item_3",@"l_item_2",@"l_item_5",@"l_item_4",@"l_item_7",nil];
    
    [self.menuView setBackgroundColor:[UIColor clearColor]];
    //默认选第一项
    [self.menuView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];

    //青奥动态
    HCYOGDynamic *HCYOGDynamicVC= [[HCYOGDynamic alloc] init];
    UINavigationController *HCYOGDynamicNav = [[UINavigationController alloc] initWithRootViewController:HCYOGDynamicVC];
    
    //3D场馆
    HCFacilityDisplayMain *HCFacilityDisplayMainVC= [[HCFacilityDisplayMain alloc] init];
    HCFacilityDisplayMainVC.delegate = self;
    UINavigationController *HCFacilityDisplayMainNav = [[UINavigationController alloc] initWithRootViewController:HCFacilityDisplayMainVC];
    
    //CCTV
    HCPlaySteam * HCPlaySteamVC = [[HCPlaySteam alloc] init];
    UINavigationController *HCPlaySteamNav = [[UINavigationController alloc] initWithRootViewController:HCPlaySteamVC];
    
    //青奥村
    HCYOGVillage *HCYOGVillageVC= [[HCYOGVillage alloc] init];
    UINavigationController *HCYOGVillageNav = [[UINavigationController alloc] initWithRootViewController:HCYOGVillageVC];
    
    
    
    _centerViewControllers = [NSArray arrayWithObjects:
                              [self.storyboard instantiateViewControllerWithIdentifier:@"homeNavCtrl"],
                              [self.storyboard instantiateViewControllerWithIdentifier:@"CEPNavCtrl"],
                              HCYOGDynamicNav,
                              HCYOGVillageNav,
                              HCFacilityDisplayMainNav,
                              @"",
                              HCPlaySteamNav,
                              @"",nil];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - TableView delegate & datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60.0;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    return 8;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"LeftMenuCell";
    LeftMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
    }
    [cell configureWithImgName:[_imgArr objectAtIndex:indexPath.row]
                         title:[_titleArr objectAtIndex:indexPath.row]
                     highColor:[_colorArr objectAtIndex:indexPath.row]];
    
    return cell;
}

//- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    return nil;
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //NSLog(@"selected index: %zd",indexPath.row);
    
//    
//    if(indexPath.row == 2){
//        NSURL *url = [[NSURL
//                       alloc]initWithString:@"yogproj://com.gfound.YOGProj"];
//        if ([[UIApplication sharedApplication] canOpenURL:url])
//        {
//            //如果能打开应⽤用
//            [[UIApplication sharedApplication] openURL:url];
//        } else {
//            //如果不能打开应⽤用 ⽤用浏览器打开应⽤用地址下载安装
//            [[UIApplication sharedApplication] openURL:[[NSURL alloc]initWithString:@"itms-services://?action=download-manifest&url=https://git.oschina.net/ios_liyun/ResProj/raw/master/YOGProj.plist"]];
//        }
//    }else if(indexPath.row==3){
//        //青奥动态
//        HCYOGDynamic *ctrl= [[HCYOGDynamic alloc] init];
//        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ctrl];
//        [self.mm_drawerController setCenterViewController:_centerViewControllers[indexPath.row]
//                                       withCloseAnimation:YES
//                                               completion:^(BOOL isfinished){
//                                               }];
//        
//    }else if(indexPath.row==4){
//        //3D
//        //TODO:和第三方协调，让ShowVenuesViewController 是
//        ShowVenuesViewController *ctl = [[ShowVenuesViewController alloc] init];
//        ctl.SceneNo = @"AYV2";
//        ctl.title = @"青奥村3D地图";
//        
//        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ctl];
//        [self presentViewController:nav animated:YES completion:nil];
//        
//
//    }else
    
        if(indexPath.row==5){
            //语言帮助
            self.mm_drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModeNone;
            
            XYAlertView *alertView = [XYAlertView alertViewWithTitle:NSLocalizedString(@"拨打电话", nil)
                                                         message:NSLocalizedString(@"拨打多语言服务热线", nil)
                                                         buttons:[NSArray arrayWithObjects:
                                                                  NSLocalizedString(@"取消", nil),
                                                                  NSLocalizedString(@"拨打", nil),nil]
                                                    afterDismiss:^(int buttonIndex) {
                                                        
                                                        if (buttonIndex == 1) {
                                                            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://4009282014"]];
                                                            
                                                        }
                                                        
                                                        self.mm_drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
                                                    }];
        
            [alertView setButtonStyle:XYButtonStyleGray atIndex:1];
            [alertView show];
            [tableView  deselectRowAtIndexPath:indexPath animated:YES];
            [self.menuView selectRowAtIndexPath:self.curIndex animated:NO scrollPosition:0];
            
            
            
            
            
            
        }else if(indexPath.row == 7){
            HomeViewController *homeVC = [[HomeViewController alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:homeVC];
            [self presentViewController:nav animated:YES completion:nil];
            self.curIndex = indexPath;
            
        }else{
        if(_centerViewControllers[indexPath.row]){
            self.curIndex = indexPath;
            [self.mm_drawerController setCenterViewController:_centerViewControllers[indexPath.row]
                                           withCloseAnimation:YES
                                                   completion:^(BOOL isfinished){
                                                   }];
        }
        
    }
    
}

@end
